<html>
<head>
<title>系统参数</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
<link rel="shortcut icon" href="resources/images/lock.png" type="image/x-icon">
<link rel="stylesheet" href="resources/css/stylemain.css">
<link rel="stylesheet" href="resources/layui/css/layui.css">

<link rel="stylesheet" href="resources/layui/css/treeTable.css">
<link rel="stylesheet" href="resources/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
<script src="resources/layui/layui.all.js"></script>
<script type="text/javascript" src="resources/js/jquery.js"></script>
<script type="text/javascript" src="resources/js/base64.js"></script>

</head>
<body>
<div class="layui-form">
  <table class="layui-hide" id="tblsys" lay-filter="tblsys"></table>
  <script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i> 编辑</button>
  </div>
  </script>
</div>

<script type="text/javascript">
var table = layui.table;

layui.use([], function(){
	getData();
	
	
	 
});

$('#ckpassword').on('keydown', function (event) {
    if (event.keyCode == 13) {
    	//debugger;
    	userckopt();
		layer.closeAll();
    }
});


function ckdialgo_auth(){
	layer.open({
		  type: 1 //0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层） 
		  ,title: "复核" //标题
		  ,skin:"layui-layer-lan"   //layui-layer-lan:蓝色，layui-layer-molv：墨绿色，默认灰色
		  ,area: ['350px', '220px'] //宽度、高度
		  ,shade: 0.3
		  ,offset: 'auto'
		  ,anim:5 //弹出动画
		  ,shadeClose: false //弹框出现后，允许点击其它地方关闭
		  ,content: $("#dlgck")     //内容
		  ,btn: ['确定', '取消'] //只是为了演示
		  ,success:function(layero){
			     var mask = $(".layui-layer-shade");
			     mask.appendTo(layero.parent());
			     $('#ckname').focus();
			     //其中：layero是弹层的DOM对象
			}
		 ,yes: function(index, layero){
		    //按钮【按钮一】的回调
		    	userckopt();
			 	layer.close(index);
		    	
			 	 
		  }
		  ,btn2: function(index, layero){
		    //按钮【按钮二】的回调
		    	
		  }
		  ,cancel: function(){ 
			    //右上角关闭回调
		 }
	});
}

table.on('toolbar(tblsys)', function(obj){
	//debugger;
	var checkStatus = table.checkStatus(obj.config.id);
    switch(obj.event){      
      case 'edit':
    	  if(checkStatus.data.length == 0){
      		layer.msg('请先选择参数项!');
      		return;
      	  }
    	  dialog_edit('','',checkStatus.data[0]);
      break;      
    };
  });

function getData(){
	$.ajax({
 		contentType: "application/json;charset=UTF-8",
 		url : "getSyslist.do?",
 		type : "get",
 		dataType : "json",
 		success : function(msg) {
 			table.render({
 				  elem: '#tblsys'
 				  ,toolbar: '#toolbarDemo'
 				  ,data:msg
 				  ,cellMinWidth: 50 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
 				  ,cols: [[
 					  {type:'radio', hide: true}
 				    ,{field:'name', title: '配置项名称', width:180} //width 支持：数字、百分比和不填写。你还可以通过 minWidth 参数局部定义当前单元格的最小宽度，layui 2.2.1 新增
 				    ,{field:'sysvalue', title: '配置项取值', width:180}
 				    ,{field:'updatetime', title: '最后更新时间', width:180}
 				    ,{field:'descriptor', title: '备注'}
 				  ]]
 				  ,height: parent.iframeH - 60
 				});	
 			
 			table.on('row(tblsys)', function(obj){
 			    var data = obj.data;    
 			    obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
 				//选中radio样式
 				obj.tr.find('i[class="layui-anim layui-icon"]').trigger("click");
 			});
 		},
 	    error : function(e){
 	    	//dispalyEasyUILoad();
 	        alert(e.status);
 	        alert(e.responseText);
 	    }
 	});
	
}


function dialog_edit(ckname,ckpassword,data){	
	layer.prompt({
		  formType: 0,
		  value: data.sysvalue,
		  title: '请输入值',
		  area: ['300px', '25px'] //自定义文本域宽高
		}, function(value, index, elem){
			editsys('','',value);
		});
}

function editsys(ckname,ckpassword,sysvalue){
	//debugger;
	var checkStatus = table.checkStatus('tblsys');
	var datastring = '{"name":"'+checkStatus.data[0].name+'","ckname":"' + ckname  + '","ckpassword":"' + ckpassword  + '","sysval":"' + sysvalue + '","rname":"系统管理/系统参数/修改参数"}';
	$.ajax({
		type:"post",
		contentType: "application/json;charset=UTF-8",
		url: "sys_edit.do?",
		async:false,
		data:datastring,
     	dataType:"json",
        success: function(msg) {    //数据提交成功时返回数据
        	//debugger;
			if(msg.status == "1"){
				getData();
        		layer.closeAll();
			}else if(msg.status == "1211"){
				$('#ckname').val('');
				$('#ckpassword').val('');
				ckdialgo_auth();
			}else{
				layer.msg(msg.desc);
			}			        			
			
        },
        error : function(e){
        	if(e.status == 200){
        		parent.location.href = "login";
        	}else{
        		alert(e.status);
                alert(e.responseText);
        	}
        }

	});
}

function userckopt(sysvalue){
	//debugger;
	var ckname = $('#ckname').val();
	if(ckname == ''){
		layer.msg('请填写用户账号!');
		return;
	}
	var ckpassword = $('#ckpassword').val();
	if(curopt == "edit"){
		editsys(ckname,$.base64.encode(ckpassword),sysvalue);
	}
	
	
}

function userckopt_cancel(){
	$('#ckname').val('');
	$('#ckpassword').val('');	
}
</script>
</body>
</html>
